home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Telnet 2.7b5 / source / tek / vgtek.c < prev    next >
Encoding:
Text File  |  1995-04-01  |  34.2 KB  |  573 lines  |  [TEXT/CWIE]

  1. mag) * xdir;
  2.             break;
  3.         case 'z': case 'x': case 'c': case 'v': case 'b': case 'n':
  4.             x += (n * vmag) * ydir;
  5.             y -= (n * vmag) * xdir;
  6.         }
  7.  
  8.         switch(c)    /* draw or move */
  9.         {
  10.         case 'r': case 't': case 'y': case 'f': case 'h':
  11.         case 'v': case 'b': case 'n':
  12.             clipvec (vw,strokex,strokey,x,y);
  13.             break;
  14.         }
  15.     
  16.     } /* end while not at end of string */
  17.  
  18.     /* Update cursor location to next char position */
  19.     savex += VGwin[vw]->charx * xdir;
  20.     savey += VGwin[vw]->charx * ydir;
  21.     if ((savex < 0) || (savex > 4095) || (savey < 0) || (savey > 3119))
  22.     {
  23.         savex = savex < 0 ? 0 : savex > 4095 ? 4095 : savex;
  24.         savey = savey < 0 ? 0 : savey > 3119 ? 3119 : savey;
  25.     }
  26.  
  27.     if (VGwin[vw]->TEKtype)
  28.         (*RG[VGwin[vw]->RGdevice].pencolor)(VGwin[vw]->RGnum,VGwin[vw]->pencolor);
  29.  
  30.     VGwin[vw]->cury = savey;
  31.     VGwin[vw]->curx = savex;
  32. }
  33.  
  34. /***********************************************************
  35. ************************************************************
  36. ***                                                         ***
  37. **    All routines given below may be called by the user      **
  38. **    program.  No routines given above may be called from  **
  39. **    the user program.                                      **
  40. ***                                                         ***
  41. ************************************************************
  42. ***********************************************************/
  43.  
  44. /*    Initialize the whole VG environment.  Should be called ONCE
  45.  *    at program startup before using the VG routines.
  46.  */
  47. void    VGinit(void)
  48. {
  49.     short i;
  50.  
  51.     for (i = 0; i < MAXVG; i++) {
  52.         VGwin[i] = nil;
  53.         }
  54.  
  55.     for (i=0; i<TEK_DEVICE_MAX; i++) (*RG[i].init)();        /* BYU LSC */
  56. }
  57.  
  58. short VGgetVS(short theVGnum)                /* NCSA 2.5: give us the VS */
  59. {                                            /* NCSA 2.5 */
  60.     if (VGcheck(theVGnum)) {
  61.         return -1;
  62.         }
  63.         
  64.     return VGwin[theVGnum]->theVS;            /* NCSA 2.5 */
  65. }                                            /* NCSA 2.5 */
  66.  
  67. static    short    VGcheck(short dnum)
  68. {
  69.     if ((dnum >= MAXVG) || (dnum < 0)) return -1;
  70.  
  71.     if (VGwin[dnum] == nil) return -1;
  72.  
  73.     return 0;
  74. }
  75.  
  76. /*
  77.  *    create a new VG window and return its number.
  78.  *    New window will be attached to specified real device.
  79.  *    Returns -1 if unable to create a new VG window.
  80.  *
  81.  *    Modified 16jul90dsw: Support selection of 4105 or 4014.
  82.  */
  83. short VGnewwin
  84.   (
  85.     short device, /* number of RG device to use */
  86.     short theVS
  87.   )
  88. {
  89.     short    vw = 0;
  90.     short    theScrn;
  91.  
  92.     while ((vw < MAXVG) && (VGwin[vw] != nil)) vw++;
  93.     if (vw == MAXVG)
  94.         return(-1);
  95.         
  96.     VGwin[vw] = (struct VGWINTYPE *) myNewPtr(sizeof(struct VGWINTYPE));
  97.     if (VGwin[vw] == nil) {
  98.         return -1;
  99.         }
  100.             
  101.     VGstore[vw] = newTEKstore();
  102.     if (VGstore[vw] == nil) {
  103.         DisposePtr((Ptr)VGwin[vw]);
  104.         VGwin[vw] = nil;
  105.         return -1;
  106.         }
  107.     
  108.     VGwin[vw]->id = 'VGWN';
  109.     VGwin[vw]->RGdevice = device;
  110.     VGwin[vw]->RGnum = (*RG[device].newwin)();
  111.  
  112.     theScrn = findbyVS(theVS);
  113.     VGwin[vw]->TEKtype = screens[theScrn].tektype;    // 0 = 4014, 1 = 4105
  114.  
  115.     if (VGwin[vw]->RGnum < 0)
  116.     {
  117.         /* no windows available on device */
  118.         DisposePtr((Ptr)VGwin[vw]);
  119.         VGwin[vw] = nil;
  120.         freeTEKstore(VGstore[vw]);
  121.         return(-1);
  122.     }
  123.             
  124.     VGwin[vw]->mode = ALPHA;
  125.     VGwin[vw]->TEKPanel = (pointlist) NULL;
  126.     VGwin[vw]->theVS = theVS;
  127.     state[vw] = DONE;
  128.     storing[vw] = TRUE;
  129.     VGwin[vw]->textcol = 0;
  130.     drawing[vw] = 1;
  131.     fontnum(vw,0);
  132.     (*RG[device].pencolor)(VGwin[vw]->RGnum,1);
  133.  
  134.     storexy(vw,0,3071);
  135. #if 1                                        /* BYU LSC */
  136.     VGzoom(vw,0,0,4095,3119);                /* BYU LSC - important */
  137. #else                                        /* BYU LSC */
  138.     VGzoom(vw,0,0,INXMAX-1,INYMAX-1);
  139. #endif                                        /* BYU LSC */
  140.     return(vw);
  141. }
  142.  
  143. /*    Release its real graphics device and its store. */
  144. void    VGclose(short vw)
  145. {
  146.     if (VGcheck(vw)) {
  147.         return;
  148.         }
  149.  
  150.     (*RG[VGwin[vw]->RGdevice].close)(VGwin[vw]->RGnum);
  151.     freeTEKstore(VGstore[vw]);
  152.     DisposePtr((Ptr)VGwin[vw]);
  153.     VGwin[vw] = nil;
  154. }
  155.  
  156. /*    Detach window from its current device and attach it to the
  157.  *    specified device.  Returns negative number if unable to do so.
  158.  *    Sample application:  switching an image from #9 to Hercules.
  159.  *    Must redraw after calling this.
  160.  */
  161. short    VGdevice(short vw, short dev)
  162. {
  163.     short newwin;
  164.  
  165.     if (VGcheck(vw)) {
  166.         return -1;
  167.         }
  168.  
  169.     newwin = (*RG[dev].newwin)();
  170.     if (newwin<0) return(newwin);    /* unable to open new window */
  171.  
  172.     (*RG[VGwin[vw]->RGdevice].close)(VGwin[vw]->RGnum);
  173.         {
  174.                     state[vw] = ESCOUT;
  175.                     savstate[vw] = HIX;
  176.                 }
  177.                 else if (value < 27)    /* ignore */
  178.                 {
  179.                     break;
  180.                 }
  181.                 else
  182.                 {
  183.                     state[vw] = DONE;
  184.                     goagain = TRUE;
  185.                 }
  186.                 break;
  187.             case 1:                        /* hix */
  188.                 vp->nhix = value;
  189.                 state[vw] = LOX;
  190.                 break;
  191.             case 2:                        /* lox */
  192.                 vp->nlox = value;
  193.                 state[vw] = DONE;
  194.                 break;
  195.             }
  196.              break;
  197.     
  198.         case LOX:                        /* must be lox */
  199.             switch(cmd)
  200.             {
  201.             case 0:
  202.                 if (value == 27)        /* escape sequence */
  203.                 {
  204.                     state[vw] = ESCOUT;
  205.                     savstate[vw] = LOX;
  206.                 }
  207.                 else if (value < 27)    /* ignore */
  208.                 {
  209.                     break;
  210.                 }
  211.                 else
  212.                 {
  213.                     state[vw] = DONE;
  214.                     goagain = TRUE;
  215.                 }
  216.                 break;
  217.             case 2:
  218.                 vp->nlox = value;
  219.                 state[vw] = DONE;
  220.                 break;
  221.             }
  222.             break;
  223.     
  224.         case ENTERVEC:
  225.             if (c == 7) vp->mode = DRAW;
  226.             if (c < 32)
  227.             {
  228.                 state[vw] = DONE;
  229.                 goagain = TRUE;
  230.                 vp->mode = DONE;
  231.                 break;
  232.             }
  233.             state[vw] = HIY;
  234.             vp->mode = TEMPMOVE;
  235.             vp->modesave = DRAW;
  236.             goagain = TRUE;
  237.             break;
  238.         case RS:
  239.             switch (c)
  240.             {
  241.             case ' ':                /* pen up */
  242.                 vp->modesave = vp->mode;
  243.                 vp->mode = TEMPMOVE;
  244.                 break;
  245.             case 'P':                /* pen down */
  246.                 vp->mode = DRAW;
  247.                 break;
  248.             case 'D':                /* move up */
  249.                 vp->cury++;
  250.                 break;
  251.             case 'E':
  252.                 vp->cury++;
  253.                 vp->curx++;
  254.                 break;
  255.             case 'A':
  256.                 vp->curx++;
  257.                 break;
  258.             case 'I':
  259.                 vp->curx++;
  260.                 vp->cury--;
  261.                 break;
  262.             case 'H':
  263.                 vp->cury--;
  264.                 break;
  265.             case 'J':
  266.                 vp->curx--;
  267.                 vp->cury--;
  268.                 break;
  269.             case 'B':
  270.                 vp->curx--;
  271.                 break;
  272.             case 'F':
  273.                 vp->cury++;
  274.                 vp->curx--;
  275.                 break;
  276.             case 27:
  277.                 savstate[vw] = RS;
  278.                 state[vw] = ESCOUT;
  279.                 break;
  280.             default:
  281. /*                storexy(vw,vp->curx,vp->cury);*/
  282.                 state[vw] = CANCEL;
  283.                 goagain = TRUE;
  284.                 break;
  285.             }
  286.             if (vp->mode == DRAW)
  287.                 clipvec(vw,vp->curx,vp->cury,vp->curx,vp->cury);
  288.             break;
  289.         case CMD0: /* *->CMD0: get 1st letter of cmd */
  290.             switch(c)
  291.             {
  292.             case 29:                    /* GS, start draw */
  293.                 state[vw] = DONE;
  294.                 goagain = TRUE;
  295.                 break;
  296.             case '%':
  297.                 state[vw] = TERMSTAT;
  298.                 break;
  299.             case '8':
  300.                 fontnum(vw,0);
  301.                 state[vw] = DONE;
  302.                 break;
  303.             case '9':
  304.                 fontnum(vw,1);
  305.                 state[vw] = DONE;
  306.                 break;
  307.             case ':':
  308.                 fontnum(vw,2);
  309.                 state[vw] = DONE;
  310.                 break;
  311.             case ';':
  312.                 fontnum(vw,3);
  313.                 state[vw] = DONE;
  314.                 break;
  315.             case 12: /* form feed = clrscr */
  316.                 if (screens[findbyVS(vp->theVS)].tekclear) {
  317.                     VGpage(vw);
  318.                     VGclrstor(vw);
  319.                 }
  320.                 break;
  321.             case 'L':
  322.                 state[vw] = SOMEL;
  323.                 break;
  324.             case 'K':
  325.                 state[vw] = IGNORE;
  326.                 break;
  327.             case 'M':
  328.                 state[vw] = SOMEM;
  329.                 break;
  330.             case 'R':
  331.                 state[vw] = SOMER;
  332.                 break;
  333.             case 'T':
  334.                 state[vw] = SOMET;
  335.                 break;
  336.             case 26:
  337.                 (*RG[vp->RGdevice].gin)(vp->RGnum);
  338.                 TEKunstore(VGstore[vw]);
  339.                 TEKunstore(VGstore[vw]);
  340.                 break;
  341.             case 10:
  342.             case 13:
  343.             case 27:
  344.             case '~':
  345.                 savstate[vw] = DONE;
  346.                 state[vw] = ESCOUT;
  347.                 break;            /* completely ignore these after ESC */
  348.             default:
  349.                 state[vw] = DONE;
  350.             }
  351.             break;
  352.         case TERMSTAT:
  353.             switch(c)
  354.             {
  355.                 case '!':
  356.                     state[vw] = INTEGER;        /* Drop the next integer */
  357.                     savstate[vw] = DONE;
  358.                     break;
  359.             }
  360.             break;
  361.         case SOMER:
  362.             switch(c)
  363.             {
  364.                 case 'A':
  365.                     state[vw] = INTEGER;
  366.                     savstate[vw] = VIEWAT;
  367.                     break;
  368.                 default:
  369.                     state[vw] = DONE;
  370.             }
  371.             break;
  372.         case VIEWAT:
  373.             state[vw] = INTEGER;
  374.             savstate[vw] = VIEWAT2;
  375.             goagain = TRUE;
  376.             break;
  377.         case VIEWAT2:
  378.             vp->TEKBackground = vp->intin < 0 ? 0 : vp->intin > 7 ? 7 : vp->intin;
  379.             state[vw] = INTEGER;
  380.             savstate[vw] = DONE;
  381.             goagain = TRUE;
  382.             break;
  383.         case SOMET:                /* Got ESC T; now handle 3rd char. */
  384.             switch(c)
  385.             {
  386.             case 'C':            /* GCURSOR */
  387.                 vp->intin = 3;
  388.                 state[vw] = STARTDISC;
  389.                 break;
  390.             case 'D':
  391.                 vp->intin = 2;
  392.                 state[vw] = STARTDISC;
  393.                 break;
  394.             case 'F':            /* set dialog area color map */
  395.                 state[vw] = JUNKARRAY;
  396.                 break;
  397.             case 'G':            /* set surface color map */
  398.                 state[vw] = INTEGER;
  399.                 savstate[vw] = JUNKARRAY;
  400.                 break;
  401.             default:
  402.                 state[vw] = DONE;
  403.             }            
  404.             break;
  405.         case JUNKARRAY:            /* This character is the beginning of an integer
  406.                                     array to be discarded.  Get array size. */
  407.             savstate[vw] = STARTDISC;
  408.             state[vw] = INTEGER;
  409.             break;                    
  410.         case STARTDISC:            /* Begin discarding integers. */
  411.             vp->count = vp->intin + 1;
  412.             goagain = TRUE;
  413.             state[vw] = DISCARDING;
  414.             break;
  415.         case DISCARDING:
  416.             /* We are in the process of discarding an integer array. */
  417.             goagain = TRUE;
  418.             if (!(--(vp->count))) state[vw] = DONE;
  419.             else if (vp->count == 1)
  420.             {
  421.                 state[vw] = INTEGER;
  422.                 savstate[vw] = DONE;
  423.             }
  424.             else
  425.             {
  426.                 state[vw] = INTEGER;
  427.                 savstate[vw] = DISCARDING;
  428.             }
  429.             break;
  430.         case INTEGER:
  431.             if (c & 0x40)
  432.             {
  433.                 vp->intin = c & 0x3f;
  434.                 state[vw] = INTEGER1;
  435.             }
  436.             else
  437.             {
  438.                 vp->intin = c & 0x0f;
  439.                 if (!(c & 0x10)) vp->intin *= -1;
  440.                 state[vw] = savstate[vw];
  441.             }
  442.             break;
  443.         case INTEGER1:
  444.             if (c & 0x40)
  445.             {
  446.                 vp->intin = (vp->intin << 6) | (c & 0x3f);
  447.                 state[vw] = INTEGER2;
  448.             }
  449.             else
  450.             {
  451.                 vp->intin = (vp->intin << 4) | (c & 0x0f);
  452.                 if (!(c & 0x10)) vp->intin *= -1;
  453.                 state[vw] = savstate[vw];
  454.             }
  455.             break;
  456.         case INTEGER2:
  457.             vp->intin = (vp->intin << 4) | (c & 0x0f);
  458.             if (!(c & 0x10)) vp->intin *= -1;
  459.             state[vw] = savstate[vw];
  460.             break;
  461.         case IGNORE:            /* ignore next char; it's not supported */
  462.             state[vw] = DONE;
  463.             break;
  464.         case IGNORE2:            /* ignore next 2 chars */
  465.             state[vw] = IGNORE;
  466.             break;
  467.         case SOMEL:                /* now process 2nd letter */
  468.             switch(c)
  469.             {
  470.             case 'E':                    /* END PANEL 25jul90dsw */
  471.                 if (vp->TEKtype)
  472.                 {
  473.                     if (vp->TEKPanel)
  474.                     {
  475.                         if ((vp->current->x != vp->savx) ||
  476.                             (vp->current->y != vp->savy))
  477.                         {
  478.                             temppoint = (pointlist) myNewPtr(sizeof(point));
  479.                             temppoint->x = vp->savx;
  480.                             temppoint->y = vp->savy;
  481.                             temppoint->next = (pointlist) NULL;
  482.                             vp->current->next = temppoint;
  483.                         }
  484.                         temppoint = vp->current = vp->TEKPanel;
  485.                         vp->savx = vp->curx = vp->current->x;
  486.                         vp->savy = vp->cury = vp->current->y;
  487.                         vp->current = vp->current->next;
  488.                         DisposPtr((Ptr) temppoint);
  489.                         PanelRgn = NewRgn();
  490.                         OpenRgn();
  491.                         while (vp->current)
  492.                         {
  493.                             clipvec(vw,vp->curx,vp->cury,
  494.                                     vp->current->x,vp->current->y);
  495.                             temppoint = vp->current;
  496.                             vp->curx = vp->current->x;
  497.                             vp->cury = vp->current->y;
  498.                             vp->current = vp->current->next;
  499.                             DisposPtr((Ptr) temppoint);
  500.                         }
  501.                         CloseRgn(PanelRgn);
  502.                         if (vp->TEKPattern <= 0)
  503.                             (*RG[vp->RGdevice].pencolor)(vp->RGnum,-vp->TEKPattern);
  504.                         PaintRgn(PanelRgn);
  505.                 /*        if (vp->TEKOutline) 
  506.                             FrameRgn(PanelRgn); */
  507.                         DisposeRgn(PanelRgn);
  508.                         (*RG[vp->RGdevice].pencolor)(vp->RGnum,vp->pencolor);
  509.                         vp->TEKPanel = (pointlist) NULL;
  510.                         vp->curx = vp->savx;
  511.                         vp->cury = vp->savy;
  512.                     }
  513.                 }
  514.                 state[vw] = DONE;
  515.                 break;
  516.             case 'F':                    /* MOVE */
  517.                 vp->modesave = vp->mode;
  518.                 vp->mode = TEMPMOVE;
  519.                 state[vw] = HIY;
  520.                 break;
  521.             case 'G':                    /* DRAW */
  522.                 vp->modesave = vp->mode;
  523.                 vp->mode = TEMPDRAW;
  524.                 state[vw] = HIY;
  525.                 break;
  526.             case 'H':                    /* MARKER */
  527.                 vp->modesave = vp->mode;
  528.                 vp->mode = TEMPMARK;
  529.                 state[vw] = HIY;
  530.                 break;
  531.             case 'I':                    /* DAINDEX 24jul90dsw*/
  532.                 state[vw] = STARTDISC;
  533.                 vp->intin = 3;
  534.                 break;
  535.             case 'L':
  536.                 state[vw] = INTEGER;
  537.                 savstate[vw] = DONE;
  538.                 break;
  539.             case 'P':                    /* BEGIN PANEL 17jul90dsw */
  540.                 if (vp->TEKtype)        /* 4105 only */
  541.                 {
  542.                     state[vw] = HIY;
  543.                     vp->mode = PANEL;
  544.                 }
  545.                 else
  546.                     state[vw] = DONE;
  547.                 break;
  548.             case 'T':                    /* GTEXT 17jul90dsw */
  549.                 if (vp->TEKtype)        /* 4105 only */
  550.                 {
  551.                     savstate[vw] = GTEXT;
  552.                     state[vw] = INTEGER;
  553.                 }
  554.                 else
  555.                     state[vw] = DONE;
  556.                 break;
  557.             default:
  558.                 state[vw] = DONE;
  559.             }
  560.             break;
  561.         case SOMEM:
  562.             switch(c)
  563.             {
  564.             case 'C':                    /* set graphtext size */
  565.                 savstate[vw] = GTSIZE0;
  566.                 state[vw] = INTEGER;
  567.                 break;
  568.             case 'L':                    /* set line index */
  569.                 savstate[vw] = COLORINT;
  570.                 state[vw] = INTEGER;
  571.                 break;
  572.             case 'M':                    /* MARKERTYPE 17jul90dsw */
  573.                 if (vp